package cn.wx.scholar.neo4j.repository;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.neo4j.annotation.Query;
import org.springframework.data.neo4j.repository.Neo4jRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import cn.wx.scholar.neo4j.entity.Neo4jPatents;

@Repository
public interface PatentsRepository extends Neo4jRepository<Neo4jPatents,Long>{
	/**
	 * 专利分页查询
	 * @param expertId
	 * @param docType
	 * @param pageable
	 * @return
	 */
	@Query(value = "match(e:expert)-[r:invention]->(p:patents) where ID(e)={expertId}  return p order by p.fPublishDate desc",
			countQuery="match(e:expert)-[r:invention]->(p:patents) where ID(e)={expertId} return count(ID(p))")
	Page<Neo4jPatents> getPatentsByExpertId(@Param("expertId") Long expertId,Pageable pageable);
	
	@Query("MATCH (n:patents) WHERE ID(n) = {id} WITH n MATCH p=(n)-[*0..1]-(m) RETURN p")
	Neo4jPatents findPatentsDetailById(@Param("id") Long id);
	
}
